Welcome to python!

1、循环dataframe

import pandas as pd

path=r"D:\Pyobject2023\object\Case\素材"

df=pd.read_excel(path+r"\1.01.xlsx")

print(df)

for index, row in df.iterrows():

s1=row["数学"]

s2=row["语文"]

print(index,s1,s2)

返回值:

姓名 数学 语文 英语
0 小明 85.5 67 84.0
1 老张 89.0 100 34.0
2 小王 95.0 55 34.0
3 小李 23.0 95 NaN
4 老六 NaN 43 99.0
5 小王 100.0 66 65.0
6 小李 13.0 22 33.0

0 85.5 67
1 89.0 100
2 95.0 55
3 23.0 95
4 nan 43
5 100.0 66
6 13.0 22